package cn.initcap.concurrency.concurrency.concurrent;

import cn.initcap.concurrency.concurrency.ThreadPoolCreatHelper;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import lombok.extern.slf4j.Slf4j;

/**
 * J.U.C是java.util.concurrent的缩写，并发容器。
 *
 * @author initcap
 * @date Created in 2018/6/16 PM3:38.
 */
@Slf4j
public class CopyOnWriteArrayListExample {

    /**
     * 同时并发执行的线程数
     */
    public static final int THREAD_TOTAL = 200;
    /**
     * 总请求数
     */
    private static final int CLIENT_TOTAL = 5000;
    private static List<Integer> list = new CopyOnWriteArrayList<>();

    public static void update(int i) {
        list.add(i);
    }

    public static void main(String[] args) throws Exception {
        ThreadPoolCreatHelper.threadFinalCountParam(CLIENT_TOTAL, THREAD_TOTAL,
                CopyOnWriteArrayListExample.class, "update",
                "CopyOnWriteArrayListExample");
        log.info("size:{}", list.size());
    }

}
